<?php
/**
 * Created by PhpStorm.
 * User: 墨染
 * Date: 2020/12/15
 * Time: 16:45
 */

/* 错误例子

$x=5; //全局变量

function myTest()
{
    $y=10; //局部变量
    echo "<p>测试函数内变量<p>";
    echo "变量 x 为：$x";
    echo "<br>";
    echo "变量 y 为：$y";
}

myTest();

echo "<p>测试函数外变量:<p>";
echo "变量 x 为: $x";
echo "<br>";
echo "变量 y 为: $y";

*/

$x=5;
$y=10;

function myTest()
{
    global $x,$y;
    $y=$x+$y;
}

myTest();
echo $y;

echo PHP_EOL; //换行

function myTest2()
{
    $GLOBALS['y']=$GLOBALS['x']+$GLOBALS['y'];
}

myTest2();
echo $y;
echo PHP_EOL;

function myTest3()
{
    static $x=0;
    echo $x;
    $x++;
    echo PHP_EOL;
}

myTest3();
myTest3();
myTest3();

?>
